home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
22
/
2
/
DISK2220.ZIP
/
SCREDIT2.EXE
/
CHGFIELD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-05
|
7KB
|
209 lines
/*
ChgField.C This small program has been provided to demonstrate how to
code routines that will:
1. Store the current screen display when a Turbo ScrEdit program
is executed and re-store the screen when the program ends.
2. Use the mouse to move the current data entry cursor from the
current field to the field that the left mouse button has
been "clicked" on.
3. Use the up and down arrow keys to move the current data entry
field up and down in columns of fields.
Step 1
To use this file for screen you create, do the following..
1 - Change "ScrDemo.006" to the name of your screen buffer.
2 - Change "ScrDemo.Scr" to the name of your screen file.
3 - Change "ChgField_Demo" to the name of your screen.
Step 2
Turbo C 2.0
Create a project file "CHGFIELD.PRJ" that contains the following
lines:
ChgField.C
ScrEditM.Lib
Turbo C ++
Open a project file with the following lines (The names
listed below will also be changed as listed above.)
Set (P)ROJECT/(O)PEN PROJECT/(L)OAD PROJECT FILE to "CHGFIELD.prj"
press (INSert) and type "CHGFIELD.C"
press (INSert) and type "ScrEditM.Lib"
Step 3
Next be sure that you..
(Turbo C 2.0) Set COMPILER/(P)RIMARY C FILE to CHGFIELD.C
Set OPTIONS/DIRECTORIES/(I)NCLUDE DIRECTORIES to include the
directory where you have stored "ScrEdit.H".
Set OPTIONS/DIRECTORIES/(L)IBRARY DIRECTORIES to include the
directory where you have stored "ScrEditM.Lib".
Set OPTIONS/COMPILER/(C)ODE GENERATION TO (M)edium
Step 4
Compile and run the program.
After you performed the steps listed above this program will
compile and run if the screen file and screen buffers are in the
current directory.
********************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <mem.h>
#include <conio.h>
#include "ScrEdit.H"
#include "ScrDemo.006"
unsigned char MaxFields;
/*
define variables to store the original screen
*/
unsigned char OriginalX, OriginalY, *OriginalScreen;
/*
This routine converts mouse cursor location into screen field
numbers.
*/
int MouseToField()
{
int loop;
loop=0;
do
{
if ((s_field->C.s_row[loop]==s_msrow) &&
(!((s_mscol<s_field->C.s_col[loop])||
(s_mscol>(s_field->C.s_col[loop]+s_field->C.s_len[loop])))))
return loop;
loop++;
}
while (loop <= MaxFields);
return s_point;
}
/*
This routine searches for the closest field on the screen that is
above or below the current field.
Dir:
If Dir = 1 Then the search is above then wrap around to bottom.
If Dir = 0 Then the search is below then wrap around to top.
*CurField:
Field number of current field when arrow key was pressed.
Op:
If Op = 1 Then move cursor to the first field located on a different
row of the screen that begins in a column equal to
or greater than the current fields column.
If Op = 0 Then move the cursor to the next field located on a different
row of the screen that begins in the same column as the
current screen field.
If Op = -1 Then move the cursor to the next field located on a different
row of the screen that begins in a colunn less than or
equal to the current fields column.
*/
int ChgField (unsigned char Dir, int *CurField, int Op)
{
int loop;
loop=*CurField;
do
{
if (Dir)
{
if (++loop > MaxFields) loop=0; /* Search UP on screen */
}
else
{
if (--loop < 0) loop=MaxFields; /* Search DOWN on screen*/
}
if ((s_field->C.s_type[loop] < 10) /* Select data entry field type 0-9 */
&& (s_field->C.s_row[loop]!= /* that are not on same row as original */
s_field->C.s_row[*CurField])) /* field */
{
switch (Op){
case 1 : /* locate prev field in column = or < current field */
/* Similar results to SHIFT TAB only skips all previous*/
/* fields on same line as current field */
{if (!(s_field->C.s_col[loop] < s_field->C.s_col[*CurField]))
{
return loop;
}
break;
}
case 0 : /* locate prev field in same column only */
{if (s_field->C.s_col[loop] == s_field->C.s_col[*CurField])
{
return loop;
}
break;
}
case -1: /* locate next field in column = or > current field */
/* Similar results to TAB only skips all remaining */
/* field on the same line as the current field. */
{if (!(s_field->C.s_col[loop] > s_field->C.s_col[*CurField]))
{
return loop;
}
break;
}
}
}
}
while (loop != *CurField); /* if current line is reached in the loop */
/* there are no qualifiying fields on the */
/* screen so return subscript of original field */
return *CurField;
}
void main()
{
delay(0); /* initialize delay function */
/* Grab original screen */
OriginalX=wherex();
OriginalY=wherey();
OriginalScreen=(unsigned char *)malloc(4000);
gettext(1,1,80,25,OriginalScreen);
/***********************/
s_init();
s_openscreenfile("ScrDemo.Scr");
initialize_ChgField_Demo_buf();
s_loadscreen("ChgField_Demo");
/*
* Pick up the maximum number of fields on the screen.. (This value
* is only available imeadiatly after the screen is loaded)
*/
MaxFields = s_indx->A.s_count[s_num]-1;
s_clearscreen(1);
s_cursor = S_NORMAL;
s_activatemouse();
s_setmouseevent("01000000");
s_showmouse();
do{
s_readscreen();
if (s_ms->mouseevent)
{
s_analizemouse();
s_point = MouseToField();
s_resetmouseflags();
}
if (s_up) s_point = ChgField(0,&s_point,0);
if (s_down) s_point = ChgField(1,&s_point,0);
}
while (!s_esc);
s_closescreenfile();
s_disablemouse();
/* restore original screen */
puttext(1,1,80,25,OriginalScreen);
gotoxy(OriginalX,OriginalY);
/***************************/
}